<% rowbg = 0 %>
<%= flash_and_form_errors(obj) %>
<% spec[:sections].each_index do |idx| section = spec[:sections][idx] %>
  <% if section[:contents] %>
    <%= section[:contents] %>
  <% else %>
    <div class="tip"><%= reqd_sym %> Indicates a required field</div>
    <table class="form <%= "section#{idx+1}" %>">
    <% action = obj.new_record? ? "create" : "update" %>
      <% if section[:name] %>
        <tr>
          <th colspan="3"><%= section[:name] %></th>
        </tr>
      <% end %>
    <% section[:fields].each do |field| %>
      <% if authorized?(:action => "#{obj.class.table_name}##{action}", :object => obj, :col => field[:col]) %>
        <tr class="rowbg<%= rowbg = 1 - rowbg %>" id="<%= field[:col] %>_row"<%= field[:hidden] ? ' style="display:none"'.html_safe : '' %>>
          <td class="name">
            <%= field[:label] || field[:col].to_s.gsub("_"," ").capitalize %>
            <%= reqd_sym(field[:required]) %>
          </td>
          <td class="value" <%= field[:expanded] ? 'colspan="2"'.html_safe : '' %>>
            <%= field[:value].html_safe rescue '' %>
          </td>
          <% unless field[:expanded] %>
            <td class="details"><%= (field[:details] || "").html_safe %></td>
          <% end %>
        </tr>
      <% end %>
    <% end %>
    </table>
  <% end %>
<% end %>

<% if controller.action_name != "show" %>
  <%= spec[:submit] || f.submit((obj.new_record? ? "Create" : "Update") + " #{obj.class.name.underscore.gsub('_', ' ').ucwords}", :class => "submit") %>
  <%= spec[:footer] %>
<% end %>

